<!DOCTYPE html>

<html>
    
    <head>
        <meta charset="UTF-8">
        <title>gl.enchant.js Plugin - debug-camera3d.gl.enchant.js - 最小サンプル</title>
        <style>
            * {
                margin: 0px;
                padding: 0px;
            }
        </style>
        
        <script type="text/javascript" src="../js/gl.enchant.js/glMatrix-0.9.5.min.js"></script>
        <script type="text/javascript" src="../js/gl.enchant.js/enchant.js"></script>
        <script type="text/javascript" src="../js/gl.enchant.js/gl.enchant.js"></script>
        <script type="text/javascript" src="../js/gl.enchant.js/primitive.gl.enchant.js"></script>
        <script type="text/javascript" src="debug-camera3d.gl.enchant.js"></script>
        <script>
            // おまじない
            enchant();
            
            // ちょっとだけ拡張
            Camera3D.prototype.setEye = function(x, y, z) { this.x = x; this.y = y; this.z = z; };
            Camera3D.prototype.setCnt = function(x, y, z) { this.centerX = x; this.centerY = y; this.centerZ = z; };
            Camera3D.prototype.setUp  = function(x, y, z) { this.upVectorX = x; this.upVectorY = y; this.upVectorZ = z; };
            
            // メイン処理
            window.onload = function() {
                var game = new Game(640, 640);
                //var game = new Game(window.innerWidth, window.innerHeight);
                game.fps = 60;
                game.keybind(90, 'a');      // z
                game.keybind(88, 'b');      // x
                game.keybind(32, "space");  // space
                
                game.onload = function() {
                    // シーン生成
                    var scene = new Scene3D();
                    
                    // ライトをセット
                    var light = new DirectionalLight();
                    light.directionZ = 1;
                    scene.setDirectionalLight(light);
                    
                    // 通常時カメラ
                    var camera = new DebugCamera();
                    camera.setDirectionFromAngle(15, 0);
                    camera.setCnt(0, 0, 0);
                    scene.setCamera(camera);
                    
                    // キューブ設置
                    for (var i=0; i<3; ++i) {
                        for (var j=0; j<3; ++j) {
                            var cube = new Cube();
                            cube.x = (j-1)*2; cube.y = 0; cube.z = (i-1)*2;
                            scene.addChild(cube);
                        }
                    }
                    
                    // 更新関数を登録
                    game.rootScene.addEventListener("enterframe", function(e) {
                        // カメラ更新
                        camera.update(game.input);
                    });
                    
                    // space キーを押した際は camera のパラメータをリセットする
                    game.addEventListener("spacebuttondown", function(e) { camera.reset(); });
                };
                
                game.start();
            };
            
        </script>
    </head>
    
    <body>
        <h1>gl.enchant.js Plugin - debug-camera3d.gl.enchant.js - 最小サンプル</h1>
    </body>
    
</html>